<?php 
// page du sous menu USERS ---> REGISTER 
include("./tetepage.php");
include("./function.php");   

// test les saisies avant d'enregistrer sur la BDD
      	if ( isset($_POST['firstname']) &&
      		  verify_name($_POST['firstname']) &&
         	  verify_name($_POST['lastname']) && 
           	  verify_email($_POST['email']) &&
           	  verify_password($_POST['password'],$_POST['verify_password']) && 
           	  verify_birth($_POST['birth']) &&
           	  verify_password($password_1, $password_2 ) &&
           	  verify_cp( $_POST['cp_cabinet'] ) &&
           	  verify_cp( $_POST['cp_livraison'] ) &&       	  
           	  verify_cp( $_POST['cp_facture'] ) &&
           	  !empty($_POST['address_cabinet']) && 
              verify_phone($_POST['phone_fixe']) &&
              !empty($_POST['password']) &&
              !empty($_POST['verify_password']) &&
              
              $_POST['email'] == $_POST['email_confirmation'] 
          		)
          	  {
               	include("./registeraction.php")  ;
          	  }     
    ?> 
<div  id="corps" >
<br/>
	<p><b>Registration</b></p>
	 
    
    <div id="image_inter_register" ></div>
    <div id="image_inter_register_2" ></div>
    <div id="image_inter_register_3" ></div>
    <div id="image_inter_register_4" ></div>
    <div id="image_inter_register_5" ></div>
    <div class="requiredField">(*)required field</div>
    <p></p>
    
    <!--   DEBUT DU FORMULAIRE     --> 
    <form method="post" action="register.php">
    		<p>
    		
  
    			<!--   FIRST NAME    -->
        		<label class="firstname"> First Name(*) </label>
				<?php 
        			if ( !empty($_POST['espion']) &&  empty($_POST['firstname'])  )
        			{
        		?> 
    					<label  class="requiredFirstname" >required field</label>
         	<?php 
         		}
         		else if(isset($_POST['firstname']) && !verify_name($_POST['firstname'])   ){
         	?>
         			<label class="requiredFirstname" > incorrect name</label>
         	<?php 
         		}
      		?>
        		<input class="firstnameTextField" type="text" size="20" name="firstname" value="<?php if(isset($_POST['firstname'])){echo $_POST['firstname'];}?>"/>
        
        
<!--  ****************************************************************************************************************************************************  --> 
			        
			        
			<!--   LAST NAME   -->     
        		<label class="lastname"> Last Name(*)</label>
        		<?php 
        		if ( !empty($_POST['espion']) &&  empty($_POST['lastname'])  )
        		{
        		?>
    					<label class="requiredLastname" >required field</label>
         	<?php 
        		}
        		else if(isset($_POST['lastname']) && !verify_name($_POST['lastname'])   ){
         	?>
    					<label class="requiredLastname" >incorrect name</label>
         	<?php 
         	}
        		?>
        		<input class="lastnameTextField" type="text" size="20" name="lastname"  value="<?php if(isset($_POST['lastname'])){ echo $_POST['lastname'];}  ?> "/>
        
 <!--  ****************************************************************************************************************************************************  -->      
       
      		<label class="dateDeNaissance"> Birthday (DD/MM/YYYY)(*)  </label>
       		<?php 
        		if ( !empty($_POST['espion']) &&  empty($_POST['birth'])  )
        		{
        		?>
    					<label class="requiredBirth" >required field</label>
         	<?php 
        		}
        		else if(  isset($_POST['birth']) && !verify_birth( $_POST['birth'] ))
        		{
        		?>
    					<label class="requiredBirth" > incorrect format</label>
         	<?php
        		}
        		?> 
        		<input class="dateDeNaissanceTextField" type="text"  name="birth"  value="<?php if(isset($_POST['birth'])){ echo $_POST['birth'];}?>"/>
       
  <!--  ****************************************************************************************************************************************************  -->  
        
        		<label class="email">Email(*)</label>
        		<?php 
        		if ( empty($_POST['email']) && !empty($_POST['espion']))
        		{
        		?>
    					<label class="requiredMail" > required field</label>
         	<?php 
        		}
        		else if( isset($_POST['email']) && alreadyAddressUsed( $_POST['email'] ) )
        		{
        		?>
    					<label class="requiredMail" > mail already used</label>
        		<?php 
        		}
        		else if( isset($_POST['email']) && !verify_email($_POST['email']) )
        		{
        		?>
    					<label class="requiredMail" > invalide Mail</label>
         	<?php 
        		}
        		?>
        		<input class="emailTextField" type="text" size="20" name="email" value="<?php if(isset($_POST['email'])){ echo $_POST['email'];}?>"/>
        
<!--  ****************************************************************************************************************************************************  --> 
        
        <label class="emailConfirmation">Email confirmation(*)</label>
        <?php 
        if ( !empty($_POST['espion']) &&  empty($_POST['email_confirmation'])  )
        {
        ?>
    				<label  class="requiredMailConfirmation" > required field</label>
         <?php 
        }
        else if( isset($_POST['email_confirmation']) && !verify_email($_POST['email_confirmation']) )
        {
          ?>
    				<label class="requiredMailConfirmation" > invalide Mail</label>
         <?php
        }
        else if( isset($_POST['email_confirmation']) && isset($_POST['email']) && $_POST['email'] != $_POST['email_confirmation']  )
        { 
			?>
    				<label  class="requiredMailConfirmation"  > not the same mail</label >
         <?php          	
         }
         ?>
        <input class="emailConfirmationTextField" type="text" size="20" name="email_confirmation"  value="<?php if(isset($_POST['email_confirmation'])){ echo $_POST['email_confirmation'];}?>"/>
 
 <!--  ****************************************************************************************************************************************************  -->        
        
        <label class="adresseLivraison"> Address delivery(*)</label>
        <?php 
      
        if ( !empty($_POST['espion']) &&  empty($_POST['address_livraison'])  )
        {
        ?>
    				<label class="requiredAL" > required field</label>
        <?php
        }
        ?>
        <input class="adresseLivraisonTextField" type="text" size="20" name="address_livraison" value="<?php if(isset($_POST['address_livraison'])){ echo $_POST['address_livraison'];}?>"/>
 
 <!--  ****************************************************************************************************************************************************  -->        
        
        <label  class="cpLivraison"> CP(*)</label>
        <?php 
        if ( !empty($_POST['espion']) &&  empty($_POST['cp_livraison'])  )
        {
        	?>
    				<label class="requiredCPL" > required field</label>
         <?php 
          }
          if( !empty($_POST['cp_livraison']) && !verify_cp($_POST['cp_livraison']) )
          {
          ?>
    				<label class="requiredCPL" > invalid CP</label>
         <?php 
          }
          ?>
         <input class="cpLivraisonTextField" type="text" size="20" name="cp_livraison" value="<?php if(isset($_POST['cp_livraison'])){ echo $_POST['cp_livraison'];} ?>"/> 
 
<!--  ****************************************************************************************************************************************************  -->  
          
          <label class="villeLivraison"> Town delivery(*)</label>
        <?php 
        if ( !empty($_POST['espion']) &&  empty($_POST['ville_livraison'])  )
        {
        		?>
    				<label class="requiredVL" > required field</label>
         <?php
        }
        else if( isset($_POST['ville_livraison']) && !verify_name($_POST['ville_livraison']) )
        {
          	?>
    				<label class="requiredVL" > invalid field</label>
         <?php
        }
        ?>
       <input class="villeLivraisonTextField" type="text" size="20" name="ville_livraison" value="<?php if(isset($_POST['ville_livraison'])){ echo $_POST['ville_livraison'];} ?>"/>

<!--  ****************************************************************************************************************************************************  -->         

        <label class="paysLivraison"> Country delivery(*)</label>      
     
       <select class="paysLivraisonTextField"  name="country_livraison" >
           <option value="france">France</option>
           <option value="spain">Spain</option>
           <option value="italy">Italy</option>
           <option value="GB">England</option>
           <option value="canada">Canada</option>
           <option value="USA">USA</option>
           <option value="china">China</option>
           <option value="japan">Japan</option>
           <option value="other">other</option>
       </select>

<!--  ****************************************************************************************************************************************************  -->  
       
       <label class="adresseFacture"> Address bill(*)</label>
        <?php 
        if ( !empty($_POST['espion']) &&  empty($_POST['address_facture'])  )
        {
        	?>
    				<label class="requiredAF" > required field</label>
         <?php
          }
          ?>
        <input class="adresseFactureTextField" type="text" size="20" name="address_facture" value="<?php if(isset($_POST['address_facture'])){ echo $_POST['address_facture'];}  ?>"/>
    
<!--  ****************************************************************************************************************************************************  --> 
    
        <label class="cpFacture"> CP(*)</label>
        <?php 
        if ( !empty($_POST['espion']) &&  empty($_POST['cp_facture'])  )
        {
        	?>
    				<label class="requiredCPF" > required field</label>
         <?php
          }
          if( !empty($_POST['cp_facture']) && !verify_cp($_POST['cp_facture']) )
          {
          echo "code postal invalide";
          }
          ?>
        <input class="cpFactureTextField" type="text" size="20" name="cp_facture" value="<?php if(isset($_POST['cp_facture'])){ echo $_POST['cp_facture'];}?>"/>
       
<!--  ****************************************************************************************************************************************************  --> 
 
        <label class="villeFacture"> Town bill(*)</label>
        <?php 
        if ( !empty($_POST['espion']) &&  empty($_POST['ville_facture'])  )
        {
        		?>
    				<label class="requiredVF" > required field</label>
         <?php
        }
        else if( isset($_POST['ville_facture']) && !verify_name($_POST['ville_facture']) )
        {
          	?>
    				<label class="requiredVF" > invalid field</label>
         <?php
        }
        ?>
        <input class="villeFactureTextField" type="text" size="20" name="ville_facture" value="<?php if(isset($_POST['ville_facture'])){ echo $_POST['ville_facture'];} ?>"/>
 
 <!--  ****************************************************************************************************************************************************  -->        
       
       <label class="paysFacture">Country bill(*)</label>
       
       <select class="paysFactureTextField" name="country_facture">
           <option value="france">France</option>
           <option value="spain">Spain</option>
           <option value="italy">Italy</option>
           <option value="GB">England</option>
           <option value="canada">Canada</option>
           <option value="USA">USA</option>
           <option value="china">China</option>
           <option value="japan">Japan</option>
           <option value="other">other</option>
       </select><br/><br/>
 
<!--  ****************************************************************************************************************************************************  -->  
       
       <label class="adresseCabinet"> Address surgery(*)</label>
        <?php 
        if ( !empty($_POST['espion']) &&  empty($_POST['address_cabinet'])  )
        {
        ?>
    				<label class="requiredAC" > required field</label>
         <?php 
          }
          ?>
         <input class="adresseCabinetTextField" type="text" size="20" name="address_cabinet" value="<?php if(isset($_POST['address_cabinet'])){ echo $_POST['address_cabinet'];}?>"/>

<!--  ****************************************************************************************************************************************************  --> 
   
        <label class="cpCabinet"> CP(*)</label>
        <?php 
        if ( !empty($_POST['espion']) &&  empty($_POST['cp_cabinet'])  )
        {
        	?>
    				<label class="requiredCPC" > required field</label>
         <?php  
          }
          if( !empty($_POST['cp_cabinet']) && !verify_cp($_POST['cp_cabinet']) )
          {
          ?>
    				<label class="requiredCPC" > invalid CP</label>
         <?php 
          }
          ?>
        <input class="cpCabinetTextField" type="text" size="20" name="cp_cabinet" value="<?php if(isset($_POST['cp_cabinet'])){ echo $_POST['cp_cabinet'];}?>"/>
        
<!--  ****************************************************************************************************************************************************  -->         

        <label class="villeCabinet"> Town surgery(*)</label>
        <?php 
        if ( !empty($_POST['espion']) &&  empty($_POST['ville_cabinet'])  )
        {
        		?>
    				<label class="requiredVC" > required field</label>
         <?php  
        }
        else if( isset($_POST['ville_cabinet']) && !verify_name($_POST['ville_cabinet']) )
        {
          	?>
    				<label class="requiredVC" > invalid field</label>
         <?php  
        }
        ?>
      <input class="villeCabinetTextField" type="text" size="20" name="ville_cabinet" value="<?php if(isset($_POST['ville_cabinet'])){ echo $_POST['ville_cabinet'];}?>"/>
 
<!--  ****************************************************************************************************************************************************  -->  
      
       <label class="paysCabinet"> Country surgery(*)</label>
       <select class="paysCabinetTextField" name="country_cabinet">
           <option value="france">France</option>
           <option value="spain">Spain</option>
           <option value="italy">Italy</option>
           <option value="GB">England</option>
           <option value="canada">Canada</option>
           <option value="USA">USA</option>
           <option value="china">China</option>
           <option value="japan">Japan</option>
           <option value="other">other</option>
       </select><br/><br/>

<!--  ****************************************************************************************************************************************************  --> 

 <label class="fixeNumber"> Phone Number(*)</label>
        <?php 
        if ( !empty($_POST['espion']) &&  empty($_POST['phone_fixe'])  )
        {
        	?>
    				<label class="requiredFixeNumber" > required field</label>
         <?php  
        }
         else  if( !empty($_POST['phone_fixe']) && !verify_phone($_POST['phone_fixe']) )
          {
          ?>
    				<label class="requiredFixeNumber" > invalid field</label>
         <?php 
          }
          ?>
        <input class="fixeNumberTextField" type="text" size="20" name="phone_fixe" value="<?php if(isset($_POST['phone_fixe'])){  echo $_POST['phone_fixe'];}  ?> "/>
 
<!--  ****************************************************************************************************************************************************  -->  
       
       <label class="phoneNumber"> Mobile Phone Number</label>
        <?php 
        if( !empty($_POST['phone']) && !verify_phone($_POST['phone']) )
          {
          		?>
    				<label class="requiredPhoneNumber" > invalid field</label>
         <?php 
          }
          ?>
        <input class="phoneNumberTextField" type="text" size="20" name="phone" value="<?php if(isset($_POST['phone'])){  echo $_POST['phone'];}  ?>"/>
 
<!--  ****************************************************************************************************************************************************  -->  
       
	<label class="login"> Login(*)</label>		       
        <?php 
        if ( !empty($_POST['espion']) &&  empty($_POST['password'])  )
        {
        	?>
    				<label class="requiredLogin" > required field</label>
         <?php 
          }
          ?> 
        <input class="loginTextField" type="password" size="20" name="password" />
 
 <!--  ****************************************************************************************************************************************************  -->      
        
        <label class="verifyLogin"> Login confirmation(*)</label>		
        <?php 
        if ( !empty($_POST['espion']) &&  empty($_POST['verify_password'])  )
        {
        	?>
    				<label class="requiredVerifyLogin" > required field</label>
         <?php
          }
          else if( !empty($_POST['password']) && !empty($_POST['verify_password']) && $_POST['password'] != $_POST['verify_password'])
          {
         	?>
    				<label class="verifyMdp" > invalid password</label>
         <?php 
          }
          ?>
       <input class="verifyLoginTextField" type="password" size="20" name="verify_password"/>
       
<!--  ****************************************************************************************************************************************************  -->       
        
			<input type="hidden" name="espion" value="jaivu" />	 
			
<!--  ****************************************************************************************************************************************************  -->          
        
         <input class="validationFormulaire" type="submit" name="submit" value="submit"/>
        
<!--  ****************************************************************************************************************************************************  --> 
      </p>
    </form>
    <p></p>
</div>
</body>
</html>